package com.ash.service.book;

import com.ash.domain.Books;
import com.ash.domain.vo.BooksVo;
import com.ash.mapper.book.BooksMapper;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : Chen Chao
 * @encoding : UTF-8
 * @date : 2021/3/23 16:35
 * @file : project06.com.ash.service.book.BookServiceImpl.java
 * @software : IntelliJ IDEA
 * @since : 1.8
 */
public class BookServiceImpl implements BookService {
    @Resource
    BooksMapper booksMapper;
    @Override
    public List<Books> selectByTypeAndName(List<Integer> bookTypes, String searchName) {
        String others=null;
        /*先判断是否选择其他类型的图书*/
        if(bookTypes!=null&&bookTypes.size()>0){
            for (Integer bookType : bookTypes) {
                if(bookType==0){
                    System.out.println("选择了其他类型");
                    others = "others";
                    break;
                }
            }
        }
        return booksMapper.selectByTypeAndName(bookTypes,others,searchName);
    }
    @Override
    public List<Books> selectAll() {
        return booksMapper.selectAll();
    }

    @Override
    public Books selectById(Integer bid) {
        return booksMapper.selectById(bid);
    }

    @Override
    public List<BooksVo> selectAll(String bname, Integer page, Integer limit) {
        return  booksMapper.selectAll(bname,(page-1)*limit,limit);
    }

    @Override
    public int dataCount(String bname) {
        return booksMapper.dataCount(bname);
    }
    @Override
    public int delete(int bid) {
        return booksMapper.delete(bid);
    }
    @Override
    public int deleteByIds(List<Integer> ids) {
        return booksMapper.deleteByIds(ids);
    }

    @Override
    public Integer add(Books books) {
        return booksMapper.add(books);
    }

    @Override
    public List<BooksVo> selectLikeAll(Integer mid, Integer grade, Integer page, Integer limit) {
        if(page!=null&&limit!=null){
            return booksMapper.selectLikeAll(mid,grade,(page-1)*limit,limit);
        }
        return booksMapper.selectLikeAll(mid,grade,null,null);
    }

    @Override
    public Integer selectLikeCount(Integer mid, Integer grade) {
        return booksMapper.selectLikeCount(mid,grade);
    }

    @Override
    public List<BooksVo> selectToCheck(Integer page, Integer limit) {
        if(page!=null&&limit!=null){
            return booksMapper.selectToCheck((page-1)*limit,limit);
        }
        return booksMapper.selectToCheck(null,null);
    }

    @Override
    public Integer selectToCheckCount() {
        return booksMapper.selectToCheckCount();
    }

    @Override
    public int check(int bid) {
        return booksMapper.check(bid);
    }

    @Override
    public int checkByIds(List<Integer> ids) {
        return booksMapper.checkByIds(ids);
    }
}
